
var   clickRowIndex = null;
$(function () {
    var sysDate = $("#khskd_sysDate").val();
    $('#grid_khskd').datagrid({
        url:$.webPath() + "/sfgl/khskd/khskdList",
        toolbar:"#toolbar_khskd",
        fitColumns:true,
        singleSelect:true,
        pagination:true,
        pageNumber: 1,
        fit:true,
        rownumbers:true,
        striped:true,
        columns:[[
            {field:'bm', title:'单据号', width:25,align: 'center'},
            {field:'sfklx', title:'收款类型', width:15,
                formatter:function (value) {
                    if (value == '3')
                        return '销售收款';
                    else
                        return '供应退款';
                } ,align: 'center'
            },
            {field:'gldw_qc', title:'关联企业', width:40,align: 'center'},
            {field:'sfje', title:'收款金额(元)', width:25,
                formatter:function(value){
                    var sl = formatJe2(value,",");
                    return sl;
                }  ,
                styler:function(){
                    return 'color:green;font-size:14px;';
                },align: 'right'
            },
            {field:'kxlx', title:'款项类型', width:15,
                formatter:function (value) {
                    if (value == '1')
                        return '预付款';
                    if (value == '2')
                        return '应付款';
                    if (value == '3')
                        return '预收款';
                    if (value == '4')
                        return '应收款';
                }   ,align: 'center'
            },
            {field:'sfkrq', title:'收款日期', width:20,
                formatter:function(value){
                    var val = formatDate(sysDate,value,5);
                    return val
                },align: 'center'},
            {field:'pjlx_z', title:'票据类型', width:15,align: 'center'},
            {field:'kxyt_z', title:'款项用途', width:15,align: 'center'},
            {field:'sbgs_jc', title:'申报公司', width:30,align: 'center'},
            {field:'sbr_xm', title:'申报人', width:15,align: 'center'},
            {field:"bz" ,title:"备注",width:20,align: 'center'},
            {field: "shrq", title: "审核日期", width: 20,align: 'center'} ,
            {field: "zt", title: "状态", width: 10,
                formatter: function (value) {
                    if (value == 'ybc') {
                        return '已保存';
                    } else if (value == 'yrz') {
                        return '已入账';
                    } else if (value == 'ysh') {
                        return '已审核';
                    }else if (value == 'ytj') {
                        return '已提交';
                    }else if (value == 'yth') {
                        return '已退回';
                    }
                },align: 'center'}

        ]],
        onLoadSuccess:function(){
        var rows =  $(this).datagrid("getRows");
            if(rows.length>0){
                $(this).datagrid("selectRow", 0);
                clickRowIndex = 0;
            }
        $(".datagrid-htable .datagrid-cell").css('text-align', 'center');
        },
    onClickRow:function(rowIndex, rowData){
        if (clickRowIndex == rowIndex)
            return;
        clickRowIndex = rowIndex;
        $('#khskd_layout').layout('remove', 'center');
        $('#khskd_layout').layout('add', {
            region: 'center',
            split: true,
            href: $.webPath() + '/sfgl/khskd/khskd_detail?khskdId=' + rowData.id
        });
    },
    onSelect: function (rowIndex, rowData) {
        if (clickRowIndex == rowIndex)
            return;
        clickRowIndex = rowIndex;
        $('#khskd_layout').layout('remove', 'center');
        $('#khskd_layout').layout('add', {
            region: 'center',
            split: true,
            href: $.webPath() + '/sfgl/khskd/khskd_detail?khskdId=' + rowData.id
        });
    }
    });
});

$("#btn_khskd_search").click(function () {
    khskd_search();
});

//查询收款管理
function khskd_search() {
    var zt = $('#khskd_zt').combobox('getValue') == null ? null : $('#khskd_zt').combobox('getValue');
    var khskdStart = $('#khskd_start').datebox('getValue');
    var khskdEnd = $('#khskd_end').datebox('getValue');
    $('#grid_khskd').datagrid('load',
        {
            bm:$('#khskd_bm').val(),
            sbgsMc:$("#khskd_sbgs").val(),
            gldwMc:$('#khskd_gldw').val(),
            zt:zt,
            skr:$('#khskd_zdr').val(),
            khskdStart:khskdStart,
            khskdEnd:khskdEnd
        }
    );
}